import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import '@/styles/index.scss'
import 'element-plus/theme-chalk/dark/css-vars.css'

// Element Plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// Element Plus Icons
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// Element Plus 中文语言包
import zhCn from 'element-plus/es/locale/lang/zh-cn'

// 权限控制
import './permission'

const app = createApp(App)
const pinia = createPinia()

// 必须先注册Pinia再使用store
app.use(ElementPlus, {
  locale: zhCn
})
// 注册Element Plus图标组件
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.use(pinia)
app.use(router)

// 在Pinia注册之后再使用store
import { useAppStore } from '@/stores/appStore'
const appStore = useAppStore()
;(window as any).appStore = appStore

app.mount('#app')